require 'test/unit'
require 'lib/smppclient/pdu/bind_receiver'

class TestBindReceiver < MiniTest::Unit::TestCase

  include SmppClient::Pdu
  include SmppClient::Util

  def test_bytes_to_object
    bb = ByteBuffer.new
    bb.append_int(58)
    bb.append_int(1)
    bb.append_int(13)
    bb.append_int(2000123456)
    bb.append_cstring('miluoki')
    bb.append_cstring('asim')
    bb.append_cstring('yakamoto')
    bb.append_byte(10)
    bb.append_byte(5)
    bb.append_byte(14)
    bb.append_cstring('romaromaromaroma')

    br = BindReceiver.new(bb)
    assert_equal(58, br.command_length)
    assert_equal(CommandId::BIND_RECEIVER, br.command_id)
    assert_equal(CommandStatus::ESME_RBINDFAIL, br.command_status)
    assert_equal(2000123456, br.sequence_number)
    assert_equal('miluoki', br.system_id)
    assert_equal('asim', br.password)
    assert_equal('yakamoto', br.system_type)
    assert_equal(10, br.interface_version)
    assert_equal(5, br.addr_ton)
    assert_equal(14, br.addr_npi)
    assert_equal('romaromaromaroma', br.address_range)
  end

  def test_object_to_bytes
    br = BindReceiver.new
    br.command_status = CommandStatus::ESME_RINVSRCADR
    br.sequence_number = 1921041
    br.system_id = 'abakan'
    br.password = 'chertog'
    br.system_type = 'closure'
    br.interface_version = 168
    br.addr_ton = Ton::NETWORK_SPECIFIC
    br.addr_npi = Npi::DATA
    br.address_range = 'all can'
    assert_equal('00000032000000010000000a001d50116162616b616e0063686572746f6700636c6f7375726500a80303616c6c2063616e00', br.buffer.to_s)
  end

end